home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2331 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Callbacks using member functions
  5. Date: 17 Jan 1996 00:13:30 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4dheva$rjl@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 16, 1996 16:43:58 in article <Callbacks using member functions>,
  15. '3mal5@qlink.queensu.ca (Lepage Marc A)' wrote: 
  16.  
  17.  
  18. >I am writing a MOTIF application, and I wish to use classes for the  
  19. >various elements of my program.  MOTIF is C, and uses callbacks.  I want  
  20. >to install member functions as the callbacks, but g++ complains, I  
  21. >suspect because of the implicit 'this' parameter.  Is there a way to get  
  22. >this to work (ie, why can't the compiler straighten everything out)? 
  23. You can't have member functions as callback directly -- except 
  24. static functions, but they're more like ordinary functions anyway. 
  25. One way to do is as follows: 
  26.  
  27. void CMyObject::SetupCallback () 
  28.  { 
  29.    XtAddCallback(xmNactivateCallback, BleepCB, (XtPointer)this); 
  30.    ... 
  31.  } 
  32.  
  33. void BleepCB (Widget w, XtPointer cd, XtPointer cbs) 
  34.  { 
  35.     CMyObject * obj = (CMyObject*)cd; 
  36.     obj->MemberFunc(.....); 
  37.  } 
  38. >I expect that I cannot use a member function as a callback, but wish to  
  39. >confirm this before I go ahead and start using friend functions. 
  40. No, excessive use of friends is not desirable. 
  41.  
  42. >Does anyone have any recommendations to structuring MOTIF applications  
  43. >with C++, and an object-oriented approach? 
  44.  
  45. IMHO Motif does not fit very well into the OO paradigm; however, you 
  46. can do a reasonable implementation if you spend a little extra 
  47. time on the design; and you know Motif reasonable well.  I 
  48. wrote a class library for Motif while learning Motif at the same time. 
  49. Needless to say, I'm not proud of that work. 
  50.  
  51. -- 
  52. Pete Grant 
  53. Kalevi, Inc. 
  54. Object Oriented Software Development
  55.